<template>
	<view>
		<block v-for="(transport, index) in transports" :key="index">
			<transport-item :data="transport" @click="detail(transport)"></transport-item>
		</block>
		<view class="uni-tab-bar-loading">
			<uni-load-more :status="loadMoreStatus"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import tradeService from '@/api/trade.js';
	import transportItem from '@/components/dogner-list-item/transport-item.vue';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			transportItem,
			uniLoadMore
		},
		data() {
			return {
				loadMoreStatus: "loading",
				transports: []
			};
		},
		methods: {
			getList: function() {
				uni.startPullDownRefresh();
				tradeService.transportList().then((res) => {
					uni.stopPullDownRefresh()
					console.log(JSON.stringify(res.data.data));
					if (res.data.success) {
						if (res.data.msg) {
							uni.showToast({
								icon: "success",
								title: res.data.msg,
								duration: 2000
							});
						}
						this.transports = res.data.data.list;
						res.data.data.list = []
						console.log(JSON.stringify(res.data.data));
						this.loadMoreStatus = "noMore"
					} else {
						if (res.data.msg) {
							uni.showToast({
								icon: "none",
								title: res.data.msg,
								duration: 2000
							});
						}
					}
				});
			},
			detail: function(transport) {
				uni.navigateTo({
					url: "/pages/transport/detail/detail?id=" + transport.id + "&action=detail"
				});
			}
		},
		onNavigationBarButtonTap: function(index) {
			uni.navigateTo({
				url: "/pages/transport/form/form?action=add"
			});
		},
		onLoad() {
			uni.getStorage({
				key: 'token'
			}).then((data) => {
				if (data[0]) {
					uni.navigateTo({
						url: "/pages/ucenter/login"
					});
				} else {
					console.log('已登录');

				}

			});

		},
		onShow() {
			this.getList();
		},
		onPullDownRefresh() {
			this.getList();

		}
	}
</script>

<style>
	.swipeout-button-group {
		height: 100%;
		line-height: 100%;
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		align-items: center;
	}

	.i-swipeout-demo-button {
		width: 160upx;
		height: 100%;
		color: #FFFFFF;
		fontsize: 20upx;
		text-align: center;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;

	}

	.i-swipeout-demo-button-edit {
		background: #007aff;
	}

	.i-swipeout-demo-button-delete {
		background: #ed3f14;
	}
</style>
